<?php


namespace app\admins\controller;


use app\BaseController;
use app\Request;
use think\facade\Db;

class Lend extends BaseController
{
    public function index(){
        return view();
    }

    public function select(){
        $result = Db::name('bookLending')
            ->alias('b')
            ->join('user c','b.user_id = c.id')
            ->field('id,name,phone')
            ->select();
        return json($result);
    }
    //    分页展示
    public function article(Request $request){

        //获取每页显示的条数
        $limit= $request->param('limit');

        $page= $request->param('page');
        $list = Db::name('bookLending')
            ->where('should_return_date','<',$request->param('time'))
            ->alias('b')
            ->join('user c','b.user_id = c.id')
            ->field('id,name,phone,state')
            ->paginate($limit,false,['page'=>$page])
            ->toArray();
        return json(['code'=>0,'msg'=>'','count'=>$list['total'],'data'=>$list['data']]);

    }


//    修改用户状态
    public function editState(){
        $data = request()->param();
        $admin = \app\model\User::find($data['id']);
        $admin->state = $data['state'];
        $ret = $admin->save();
        if($ret){
            return  json(["state"=>200]);
        }
        else{
            return json(["state"=>204,"message"=>'修改状态失败']);
        }
    }

}